<?php
namespace App\Http\Middleware;

use Closure;

/**
 * 后台中间个登陆验证的处理
 * Class AdminAuthMiddleware
 * @package App\Http\Middleware
 */
class AdminAuthMiddleware
{
    /**
     * 处理传入的请求
     * @param $request
     * @param Closure $next
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed
     */
    public function handle($request, Closure $next){
        $sessionData = $request->session()->get('admin_user');
        if(empty($sessionData)){
            return redirect('admin/loginIndex');
        }
        if($sessionData['expire_time'] < time()){
            return redirect('admin/loginOut');
        }

        $request->attributes->add(['admin_user_data'=>$sessionData]);

        return $next($request);
    }
}
